package com.itheima.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
        Class aClass = Class.forName("com.itheima.reflect.Student");
        Field[] field = aClass.getFields();
        for (Field f : field) {
            System.out.println(f);
        }
        System.out.println("---------------");
        Field[] fields = aClass.getDeclaredFields();
        for (Field f : fields) {
            System.out.println(f);
        }
        System.out.println("---------------");
        Field id = aClass.getDeclaredField("id");
        System.out.println("id = " + id);
        System.out.println("--------------");

        Field money = aClass.getDeclaredField("money");
        money.setAccessible(true);
        /*Constructor constructor = aClass.getConstructor();
        Student stu = (Student) constructor.newInstance();*/
        Student stu = (Student) aClass.newInstance();
        money.set(stu, 500);
        System.out.println(stu);
    }
}
